<!--# layout("/common/layout.html",{"jsBase":"/js/content/ebookChapter/"}){ -->
<style>
    .layui-form-select dl{
        z-index: 1000;
    }
</style>
<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="chapterId" id="chapterId">
    <input type="hidden" name="bookId" id="bookId" value="${bookId}">
    <input type="hidden" name="chapterContent" id="chapterContent" >
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">章节序号</label>
				<div class="layui-input-inline">
                                <input type="text" name="chapterNo" id="chapterNo" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required|number">
				</div>
            </div>
            <div class="layui-inline">
            <label class="layui-form-label">章节页码</label>
				<div class="layui-input-inline">
                                <input type="text" name="pageNo" id="pageNo" autocomplete="off" maxlength="50" class="layui-input" >
				</div>
            </div>
            <div class="layui-inline">
            <label class="layui-form-label">章节标题</label>
				<div class="layui-input-inline">
                                <input type="text" name="chapterTitle" id="chapterTitle" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required">
				</div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">章节类型</label>
				<div class="layui-input-inline">
                    <select style="width:40%" class="select" name="chapterType" id="chapterType"  promtion="请选择类型" lay-verify="required">
                        <option value="">请选择类型</option>
                        <option value="1">普通章节</option>
                        <option value="2">大章节</option>
                        <option value="3">无内容章节</option>
                    </select>
				</div>
            </div>
            <div class="layui-inline">
            <label class="layui-form-label">上级章节</label>
				<div class="layui-input-inline">
                    <layui:simpleDataSelect name="pChapterId" value="${has(ebookChapter)?ebookChapter.pChapterId:''}" data="${pChapterIdList}"
                                            attrId="chapterId" attrName="chapterTitle" laySearch="true" style="width:200px"/>
				</div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">章节价格</label>
                <div class="layui-input-inline">
                    <input type="text" name="chapterPrice" id="chapterPrice" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required|number">
                </div>
            </div>
        </div>
    </div>



    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">是否免费</label>
				<div class="layui-input-inline">
                    <input type="radio" name="isFree" value="1" ${ebookChapter.isFree==1?'checked':''} title="是" lay-verify="required">
                    <input type="radio" name="isFree" value="0" checked title="否" lay-verify="required">
				</div>
            </div>

            <div class="layui-inline">
            <label class="layui-form-label">可用标记</label>
				<div class="layui-input-inline">
                    <input type="radio" name="chapterStatus"  value="1" checked title="是" lay-verify="required">
                    <input type="radio" name="chapterStatus"  value="0" ${ebookChapter.chapterStatus==0?'checked':''} title="否" lay-verify="required">
				</div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                  <layui:singleFile id="url" tagName="下载地址" tips=""/>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">章节内容</label>
                <div class="layui-input-block" style="width:712px">
                    <script id="chapterContentUE" type="text/plain" placeholder="请输入" >
                        ${ebookChapter.chapterContent}
                    </script>
                </div>
            </div>
        </div>
    </div>

    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.all.js"></script>
<script>
    let ueditor_config = {
        toolbars: [["undo", "redo", "|", "fontsize", "forecolor", "bold", "italic", "underline", "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "lineheight", "|", "directionalityltr", "directionalityrtl", "indent", "|", "simpleupload", "|",  "spechars", "source", "|", "searchreplace", "|", "fullscreen","mobile"]],
        serverUrl: "${ctxPath}/content/ebookChapter/config",
        autoHeightEnabled: false,
        elementPathEnabled : false,　　//是否启用元素路径，默认是true显示
        wordCount:false,          //是否开启字数统计
        initialFrameHeight:500
    };
    var ue = UE.getEditor('chapterContentUE',ueditor_config);

    ue.ready(function() {
        // ue.execCommand('insertHtml','${ebookChapter.chapterContent}');
    });

    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {
            console.log("upload");
            return '${ctxPath}/content/ebookChapter/upload.json';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }

    layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','ebookChapterApi'], function(exports) {
    var form = layui.form;
    var ebookChapterApi = layui.ebookChapterApi;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(ebookChapterJson))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                $("#chapterContent").val(ue.getContent());
                form.on('submit(form)', function(){
                    ebookChapterApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(ebookChapterJson))){  -->
    var formJson = ${ebookChapterJson};
    form.val("editform",formJson);
    $(".file_link").each(function() {
        var a=document.createElement('a');
        var aJq = $(a);
        aJq.html("下载文件");
        aJq.attr("href",formJson[$(this).attr("id")]);
        aJq.attr("target","_blank");
        $(this).append(aJq);
    });
    <!--# } -->
});
</script>
